%{
#include "exp_parser.h"
#include "data_memory.h"

#include <stdio.h>
%}

%option outfile="./exp_lexer.c" header-file="./exp_lexer.h"
%option warn nodefault
%option reentrant noyywrap never-interactive nounistd
%option bison-bridge

%%

"+" { return OP_ADD; }
"-" { return OP_SUB; }
"*" { return OP_MUL; }
"/" { return OP_DIV; }
"(" { return LPAREN; }
")" { return RPAREN; }

"==" { return COP_EQ; }
">=" { return COP_GE; }
"<=" { return COP_LE; }
">" { return COP_GT; }
"<" { return COP_LT; }

    /* a-z为变量 */   
[a-zA-Z_][a-zA-Z0-9_]* {
    // yylval->ival = DataMemory::get_val(yytext);
    yylval->sval = strdup(yytext);
    return IDENTIFIER;
}

    /* 整数 */
[0-9]+ {
    yylval->ival = atoi(yytext);
    return INTEGER;
}

    /* 空白被忽略 */
[ \t] ;

    /* 其他字符都是非法的 */
. {
    fprintf(stderr, "\033[31mERROR\033[0m: Unrecognized symbol: \033[34m%s\033[0m\n", yytext);
    exit(1);
}

%%